<?php

  require_once "base.class.php";

  /**
   * This class implements INI parser for ini files such 'php.ini'.<br />
   * Store the path to the file in private variable and parse the entire file.<br />
   *
   * @param string $filename The full path to the ini file.
   *
   * @author Dany Mottier
   * @version 1.1
   */
  class IniParser extends Base {

    /** @var array It will contain each pair key/value contained in the parsed ini file. */
    public $Items = array();

    /** @var string The full path to the file to parse. */
    var $filename = "";

    // -------------------------------------------------------------------------

    /**
     * Store the path file in private variable and parse the entire file.
     * @param String $filename The full path to the ini file.
     */
    public function __construct(IString $filename) {
      $this->filename = $filename->toString();
      $this->parse();
    }

    // -------------------------------------------------------------------------

    /**
     * Returns the path file.
     * @return String The filename.
     */
    public function getFileName() {
      return new String(basename($this->filename));
    }

    // -------------------------------------------------------------------------

    /**
     * Parse the entire ini file and set each pair key/value in the Items collection.
     * @link http://be2.php.net/manual/en/function.parse-ini-file.php
     */
    private function parse() {
      $this->Items = parse_ini_file($this->filename, TRUE);
    }

    /**
     * Returns the value of an indexed key in the Items collection.
     * @param String $section The section to browse.
     * @param String $key The key to pick up the value.
     * @return String The value of the key.
     */
    public function getValue(IString $section, IString $key) {
      return $this->Items[$section->toString()][$key->toString()];
    }

  }

?>
